﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;

namespace Lingmeng.EntityFrameworkCore.MySql
{
    public static class LingmengEntityFrameworkCoreMySqlExtension
    {
        public static IServiceCollection AddMySqlEntityFrameworkCore<IDbContext>(this IServiceCollection services,string connect)
            where IDbContext : MasterDbContext<IDbContext>
        {
            var configuration = (IConfiguration?)services.BuildServiceProvider().GetRequiredService<IConfiguration>();

            services.AddEntityFrameworkCore<IDbContext>(options=>
            {
                options.UseMySql(configuration.GetConnectionString(connect),new MySqlServerVersion(new Version(8,0,32)),x=>x.EnableRetryOnFailure());
            });
            return services;
            
        }
        
    }
}